from __future__ import print_function
import sys

"""@package extras.commons
The default commons module for the TAG Engine.

Everything here can be overwritten by specifying the same name with your module. 
Things here can only be accessed via gameInstance.extras.get('commons.<name>')"""

def output(msg, sep=" ", end="\n", file=sys.stdout):
    """Default output function
    
    This function is the default function for printing messages.
    This prints to console. It is a wrapper of the built-in print function from __future__"""
    # stops printing if the msg is empty; this is why this should be refactored.
    if str(msg) == "":
        return
    
    print(str(msg), sep=sep, end=end)

def getInput(txt=">> ", notLower=False):
    """Default getting input
    
    This function gets the input from console. Takes 2 argument
    @param txt The text you want it to show when before the input block.
    @param notLower a boolean value that tells if the return should be all lowercase or not.
    @return Returns input string.
    """
    # ISSUE: This won't satisfy GUI requirement as getInput returns something.
    if notLower: 
        return raw_input(txt)
    return raw_input(txt).lower()

def mainLoop(game):
    """ The default main loop function of the game.  
    
    This function gets the command from console. Returns True or False upon winning or losing.
    @param game A game instance"""
    while game.running:
        if game.win():
            return True
        if self.lose():
            return False
        
        cmd = game.getInput()
        game.performCommand(cmd)
        
        game.update()

flags = {"prefix" : "commons."}
imports = {"output" : output, "getInput" : getInput, "mainLoop" : mainLoop}